package com.muyu.system.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.system.domain.DanmoShoppingSubcategory;
import com.muyu.system.service.IDanmoShoppingSubcategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品子分类Controller
 *
 * @author yangle
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/subcategory")
public class DanmoShoppingSubcategoryController extends BaseController
{
    @Autowired
    private IDanmoShoppingSubcategoryService danmoShoppingSubcategoryService;

    /**
     * 查询商品子分类列表
     */
//    @RequiresPermissions("system:subcategory:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoShoppingSubcategory danmoShoppingSubcategory)
    {
        List<DanmoShoppingSubcategory> list = danmoShoppingSubcategoryService.selectDanmoShoppingSubcategoryList(danmoShoppingSubcategory);
        return Result.success(list);
    }

    /**
     * 导出商品子分类列表
     */
//    @RequiresPermissions("system:subcategory:export")
    @Log(title = "商品子分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoShoppingSubcategory danmoShoppingSubcategory)
    {
        List<DanmoShoppingSubcategory> list = danmoShoppingSubcategoryService.selectDanmoShoppingSubcategoryList(danmoShoppingSubcategory);
        ExcelUtil<DanmoShoppingSubcategory> util = new ExcelUtil<DanmoShoppingSubcategory>(DanmoShoppingSubcategory.class);
        util.exportExcel(response, list, "商品子分类数据");
    }

    /**
     * 获取商品子分类详细信息
     */
//    @RequiresPermissions("system:subcategory:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoShoppingSubcategoryService.selectDanmoShoppingSubcategoryById(id));
    }

    /**
     * 新增商品子分类
     */
//    @RequiresPermissions("system:subcategory:add")
    @Log(title = "商品子分类", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoShoppingSubcategory danmoShoppingSubcategory)
    {
        return toAjax(danmoShoppingSubcategoryService.insertDanmoShoppingSubcategory(danmoShoppingSubcategory));
    }

    /**
     * 修改商品子分类
     */
//    @RequiresPermissions("system:subcategory:edit")
    @Log(title = "商品子分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoShoppingSubcategory danmoShoppingSubcategory)
    {
        return toAjax(danmoShoppingSubcategoryService.updateDanmoShoppingSubcategory(danmoShoppingSubcategory));
    }

    /**
     * 删除商品子分类
     */
//    @RequiresPermissions("system:subcategory:remove")
    @Log(title = "商品子分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoShoppingSubcategoryService.deleteDanmoShoppingSubcategoryByIds(ids));
    }
}
